package com.zoo.wuhua.config;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <b>fastjson自定义转换器</b><br>
 *
 * @author zhangli7@yusys.com.cn
 * @since 2019年11月1日 上午8:42:32
 */
@Configuration
public class FastjsonConfig {

    @Bean
    FastJsonHttpMessageConverter fastjsonConverter() {

        // 创建fastjson对象
        FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();

        FastJsonConfig config = new FastJsonConfig();
        // 设置是否需要格式化
        config.setSerializerFeatures(SerializerFeature.PrettyFormat,
                SerializerFeature.QuoteFieldNames, SerializerFeature.WriteEnumUsingToString,
                SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat,
                SerializerFeature.DisableCircularReferenceDetect);
        config.setDateFormat("yyyy-MM-dd");
        converter.setFastJsonConfig(config);
        return converter;
    }
}
